<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html class="x-admin-sm">

<head>
  <meta charset="UTF-8">
  <title>后台管理</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport"
    content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
  <link rel="stylesheet" href="/admin/static/css/font.css">
  <link rel="stylesheet" href="/admin/static/css/xadmin.css">
  <script type="text/javascript" src="/admin/static/js/jquery.min.js"></script>
  <script type="text/javascript" src="/admin/static/lib/layui/layui.js" charset="utf-8"></script>
  <script type="text/javascript" src="/admin/static/js/xadmin.js"></script>

  <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
  <!--[if lt IE 9]>
      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body>
  <div class="x-body">
    <form class="layui-form" action="/admin/machine/add" method="POST" enctype="multipart/form-data">
      <div class="layui-form-item">
        <label for="L_name" class="layui-form-label">
          <span class="x-red">*</span>名称
        </label>
        <div class="layui-input-inline">
          <input type="text" id="L_name" name="name" required="" lay-verify="machine_name" autocomplete="off"
            class="layui-input">
        </div>
      </div>
      <div class="layui-form-item">
        <label for="L_model" class="layui-form-label">
          <span class="x-red">*</span>型号
        </label>
        <div class="layui-input-inline">
          <input type="text" id="L_model" name="model" required="" lay-verify="model" autocomplete="off"
            class="layui-input">
        </div>
      </div>
      <div class="layui-form-item">
        <label for="L_factory" class="layui-form-label">
          <span class="x-red">*</span>厂商
        </label>
        <div class="layui-input-inline">
          <input type="text" id="L_factory" name="factory" required="" lay-verify="factory" autocomplete="off"
            class="layui-input">
        </div>
      </div>
      <div class="layui-form-item">
        <label for="L_parameter" class="layui-form-label">
          <span class="x-red">*</span>技术参数
        </label>
        <div class="layui-input-inline">
          <input type="text" id="L_parameter" name="parameter" required="" lay-verify="parameter" autocomplete="off"
            class="layui-input">
        </div>
      </div>
      <div class="layui-form-item">
        <label for="L_function" class="layui-form-label">
          <span class="x-red">*</span>功能
        </label>
        <div class="layui-input-inline">
          <input type="text" id="L_function" name="function" required="" lay-verify="function" autocomplete="off"
            class="layui-input">
        </div>
      </div>
      <div class="layui-form-item">
        <label for="" class="layui-form-label">
          <span class="x-red">*</span>图片
        </label>
        <button type="button" class="layui-btn" id="file-btn">
          <i class="layui-icon">&#xe67c;</i>选择图片
        </button>
        <input type="file" name="img" id="file-input" style="display: none" lay-verify="required" accept="image/*">
        <span id="show"></span>
      </div>

      <div class="layui-form-item">
        <label for="L_repass" class="layui-form-label">
        </label>
        <button class="layui-btn" lay-filter="modify" lay-submit="">
          增加
        </button>
      </div>
    </form>
  </div>
  <script>
    $('#file-btn').on('click', function () {
      $('#file-input').click();
    });
    $('#file-input').on('change', function () {
      $('#show').text(this.files[0].name)
    });
    layui.use(['form', 'layer'], function () {
      $ = layui.jquery;
      var form = layui.form
        , layer = layui.layer;

      //自定义验证规则
      form.verify({
        machine_name: function (value) {
          if (value.length < 1) {
            return '名字不能为空';
          } else if (value.length > 50) {
            return '名字不能大于50个字符';
          }
        },
        model: function (value) {
          if (value.length < 1) {
            return '型号不能为空';
          } else if (value.length > 20) {
            return '型号不能大于20个字符';
          }
        },
        factory: function (value) {
          if (value.length < 1) {
            return '厂商不能为空';
          } else if (value.length > 50) {
            return '厂商不能大于50个字符';
          }
        },
        parameter: function (value) {
          if (value.length < 1) {
            return '参数不能为空';
          } else if (value.length > 50) {
            return '参数不能大于50个字符';
          }
        },
        function: function (value) {
          if (value.length < 1) {
            return '功能不能为空';
          } else if (value.length > 50) {
            return '功能不能大于50个字符';
          }
        }
      });
    });
  </script>
</body>

</html>